/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Netz;

/**
 * Dieses Fenster dient dazu dem Spieler anzuzeigen wenn er eine Einladung zu einem Spiel bekommt.
 * @author Daniel Mueller, Phillip Hertel, Jonas Hauff
 */
public class Herausforderung extends javax.swing.JFrame {

    private NetzeClient client;
    /**
     * Creates new form Herausforderung
     */
    public Herausforderung() {
        initComponents();
    }
    /**
     * Das Label für den Namen des Herausforders wird auf den in Parameter übergegenen Namen geändert.
     * @param pName 
     */
    public void setpName(String pName)
    {
        jLabelName.setText(pName);
    }
    /**
     * Der Client wird übergeben, damit später die Methode pSend vom Client abgerufen werden kann.
     * @param pClient 
     */
    public void setClient(NetzeClient pClient)
    {
        client = pClient;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabelName = new javax.swing.JLabel();
        jButtonAnnehmen = new javax.swing.JButton();
        jButtonAblehnen = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();

        jLabel1.setText("Folgender Spieler möchte dich herausfordern:");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabelName.setText("Name");

        jButtonAnnehmen.setText("annehmen");
        jButtonAnnehmen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAnnehmenActionPerformed(evt);
            }
        });

        jButtonAblehnen.setText("ablehnen");
        jButtonAblehnen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAblehnenActionPerformed(evt);
            }
        });

        jLabel3.setText("           Folgender Spieler fordert dich heraus:");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(88, 88, 88)
                        .addComponent(jLabelName, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 246, Short.MAX_VALUE)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jButtonAnnehmen, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jButtonAblehnen, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabelName, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonAnnehmen)
                    .addComponent(jButtonAblehnen))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    /**
     * Die Herausforderung wird angenommen und es wird an den Server die Annahme gesendet.
     * @param evt 
     */
    private void jButtonAnnehmenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAnnehmenActionPerformed
        client.pSend("Spiel annehmen: "+jLabelName.getText());
        this.setVisible(false);
    }//GEN-LAST:event_jButtonAnnehmenActionPerformed
    /**
     * Die Herausforderung wird abgehlent und die Ablehnung wird an den Server gesendet.
     * @param evt 
     */
    private void jButtonAblehnenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAblehnenActionPerformed
        client.pSend("Spiel ablehnen: "+jLabelName.getText());
        this.setVisible(false);
    }//GEN-LAST:event_jButtonAblehnenActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Herausforderung.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Herausforderung.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Herausforderung.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Herausforderung.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Herausforderung().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonAblehnen;
    private javax.swing.JButton jButtonAnnehmen;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabelName;
    // End of variables declaration//GEN-END:variables
}
